// 1.引入公用样式表
require("../../assets/css/index.less");
// require("../../assets/fonts/iconfont.css")

// 2.引入当前样式表
require("./badge.less");

// 引入插件

// 3.引入公用js模块
let validator = require("../../utils/validator.js");
let https = require("../../utils/https.js");
let local = require("../../utils/local.js");

// 4.引入工具函数
let dom = require("../../utils/dom.js");
dom.ready(function () {
	// 获取排名
	dom.$("#rankTxt").innerHTML = local.get("user").ranking;

	// 获取徽章
	function getBadge() {
		let badgeArr = [
			require("../../assets/imgs/mybadge01.jpg"),
			require("../../assets/imgs/mybadge02.jpg"),
			require("../../assets/imgs/mybadge03.jpg"),
			require("../../assets/imgs/mybadge04.jpg"),
			require("../../assets/imgs/mybadge05.jpg"),
			require("../../assets/imgs/mybadge06.jpg"),
			require("../../assets/imgs/mybadge07.jpg"),
			require("../../assets/imgs/mybadge08.jpg"),
		];
		let lastImg = require("../../assets/imgs/mybadge09.jpg");
		// 发送请求获取徽章数据
		https.get("/api/exercise/badge", function (res) {
			// 遍历渲染
			// let liNode = "";
			res.data.forEach((v) => {
				console.log(v);
				dom.$("#badges ul").innerHTML += `
                <li>
                    <img src="${badgeArr[v.id - 1]}" alt="" />
                    <span>${v.name}</span>
				</li>`;
			});
			let lastLi = `
            <li>
                <img src="${lastImg}" alt="" />
            </li>`;
			dom.$("#badges ul").innerHTML += lastLi;
		});
	}
	getBadge();
	// 跳转到我的页面
	dom.goTo("#header span", "user");
});
